package com.bw.zg3.Cate.WX

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.facade.annotation.Route
import com.bw.base.mvvm.BaseActivity
import com.bw.zg3.R
import com.bw.zg3.databinding.ActivityWxactivityBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
@Route(path = "/app/WXActivity")
@AndroidEntryPoint
class WXActivity :BaseActivity<ActivityWxactivityBinding,WXViewModel>() {

        val wxApter by lazy { WXApter() }
    override fun initView() {
        binding.rv.apply {
            adapter=wxApter
        }
        lifecycleScope.launch {
            vm.WxResUlt().collect{
                wxApter.submitData(it)
            }
        }
        ItemTouchHelper(object :ItemTouchHelper.Callback(){
            override fun getMovementFlags(
                recyclerView: RecyclerView,
                viewHolder: RecyclerView.ViewHolder,
            ): Int {
                val left = ItemTouchHelper.LEFT
                return makeMovementFlags(0,left)

            }

            override fun onMove(
                recyclerView: RecyclerView,
                viewHolder: RecyclerView.ViewHolder,
                target: RecyclerView.ViewHolder,
            ): Boolean {
                return true
            }

            override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
                val layoutPosition = viewHolder.layoutPosition
                wxApter.notifyItemRemoved(layoutPosition)



            }

        }).attachToRecyclerView(binding.rv)
    }

    override fun intiData() {

    }
}